package com.tsd.jxc.fin.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.fin.dao.JxcFinanceQueMapper;
import com.tsd.jxc.fin.entity.JxcFinanceQue;
import com.tsd.jxc.fin.entity.JxcFinanceQueExt;
import com.tsd.jxc.fin.service.JxcFinanceQueService;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：JxcFinanceQue 服务实现层
 *
 * @author Hillpool
 * @date 2022/09/02 16:42:49
 */
@Service
public class JxcFinanceQueServiceImpl extends BaseServiceImpl implements JxcFinanceQueService {

    @Resource
    private JxcFinanceQueMapper jxcFinanceQueMapper;

    @Override
    public JxcFinanceQue getJxcFinanceQueById(Long id) throws Exception {
        return jxcFinanceQueMapper.selectByPrimaryKey(id);
    }

    @Override
    public JxcFinanceQueExt queryBySid(String sid) throws Exception {
        return jxcFinanceQueMapper.selectBySid(sid);
    }

    @Override
    public void deleteJxcFinanceQues(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            JxcFinanceQue old = jxcFinanceQueMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            jxcFinanceQueMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveJxcFinanceQue(JxcFinanceQue record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            jxcFinanceQueMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            jxcFinanceQueMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<JxcFinanceQueExt> findJxcFinanceQues(Map<String, Object> params, PageBean page) throws Exception {
        return jxcFinanceQueMapper.selectByPage(params, page);
    }

    @Override
    public List<JxcFinanceQueExt> findJxcFinanceQues(Map<String, Object> params) throws Exception {
        return jxcFinanceQueMapper.selectByParams(params);
    }
}